
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.get('https://liuyan.people.com.cn/threads/list?fid=5052&formName=%E5%9B%BD%E5%AE%B6%E5%8F%91%E5%B1%95%E5%92%8C%E6%94%B9%E9%9D%A9%E5%A7%94%E5%91%98%E4%BC%9A%E5%85%9A%E7%BB%84%E4%B9%A6%E8%AE%B0%E3%80%81%E4%B8%BB%E4%BB%BB%E9%83%91%E6%A0%85%E6%B4%81&position=1')
    while True:
        try:
            driver.implicitly_wait(30)
            y = -1
            real_y = driver.execute_script('return window.scrollY')
            while real_y != y:
                y = real_y
                time.sleep(1)
                driver.execute_script('window.scrollBy(0,100)')
                real_y = driver.execute_script('return window.scrollY')

            ele = driver.find_element(By.XPATH, '//div[@class="mordList"]')
            time.sleep(1)
            ele.click()
        except:
            print('找不到了')
            break
    data_lis = driver.find_elements(By.XPATH, '//ul[@class="replyList"]/li')
    #
    for li in data_lis:
        # t1 = li.find_element(By.XPATH, './div[@class="tabList fl"]/h1').text
        t2 = li.find_element(By.XPATH, './p[@class="replyContent"]/span[1]').text
        print(t2)
    time.sleep(3)
    driver.quit()







